package com.SjwProject.StudentSystem;

import com.SjwProject.domain.Student;
import org.w3c.dom.ls.LSOutput;

import java.sql.ClientInfoStatus;
import java.util.ArrayList;
import java.util.Scanner;

public class TestMain {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        LO:
        while (true) {
            System.out.println("--------欢迎进入学生管理系统---------");
            System.out.println("1、添加学生");
            System.out.println("2、删除学生");
            System.out.println("3、查询学生");
            System.out.println("4、修改学生");
            System.out.println("5、退出");
            System.out.println("请输入您的选择");
            int t = sc.nextInt();
            switch (t) {
                case 1:
                    // System.out.println("添加学生");
                    ks:
                    while (true) {
                        Student stn = GetStudent(sc);
                        list.add(stn);
                        System.out.println("添加成功");
                        System.out.println("*、返回上一级");
                        System.out.println("-、继续添加");
                        String d = sc.next();
                        if ("*".equals(d)) {
                            break ks;
                        }
                    }
                    break;
                case 2:
                    sc:
                    while (true) {
                        System.out.println("请输入要删除学生的学号或输入*退回上一级");
                        String f = sc.next();
                        if ("*".equals(f)) {
                            break sc;
                        } else {
                            int k = Integer.parseInt(f);
                            int index = GetIndex(list, k);
                            if (index == -1) {
                                System.out.println("学号不存在");
                            } else {
                                list.remove(index);
                                System.out.println("删除成功");
                                break sc;
                            }
                        }
                    }
                    break;
                case 3:
                    ge:
                    while (true) {
                        System.out.println("请输入要查询的学生学号或输入*返回上一级");
                        String g = sc.next();
                        if ("*".equals(g)) {
                            break ge;
                        } else {
                            int a = Integer.parseInt(g);
                            SetStudent(list, a);
                        }

                    }


                    break;
                case 4:
                    s:
                    while (true) {
                        System.out.println("请输入要修改的学生的学号或输入*退回上一级");
                        String h = sc.next();
                        if ("*".equals(h)) {
                            break s;
                        } else {
                            int k = Integer.parseInt(h);
                            int index = GetIndex(list, k);
                            if (index == -1) {
                                System.out.println("学号不存在");
                            } else {

                            }
                        }
                    }
                    break;
                case 5:
                    System.out.println("感谢使用");
                    break LO;
                default:
                    System.out.println("请输入正确选项");
                    break;
            }
        }


    }

    private static int GetIndex(ArrayList<Student> list, int f) {
        int index = -1;
        for (int i = 0; i < list.size(); i++) {
            Student jk = list.get(i);
            int jj = jk.getSid();
            if (jj == f) {
                f = index;
            }
        }
        return index;
    }

    private static void SetStudent(ArrayList<Student> list, int a) {
        if (list.size() == 0) {
            System.out.println("请先添加学生信息");
            return;//方法弹栈消失不在继续执行
        }
        for (int i = 0; i < list.size(); i++) {
            if (a == list.get(i).getSid()) {
                System.out.println("学号\t姓名\t年龄\t生日");
                System.out.println(list.get(i).getSid() + "\t" + list.get(i).getName() + "\t" + list.get(i).getAge() + "\t" + list.get(i).getBirthday());

            }
        }
    }


    private static Student GetStudent(Scanner sc) {
        System.out.println("请输入学生学号");
        int sid = sc.nextInt();
        System.out.println("请输入学生姓名");
        String name = sc.next();
        System.out.println("请输入学生年龄");
        String age = sc.next();
        System.out.println("请输入学生生日");
        String birthday = sc.next();
        Student stn = new Student(sid, name, age, birthday);
        return stn;
    }


}
